#ifndef _OM_SINGLETON_H_
#define _OM_SINGLETON_H_

#include "OmPrerequisite.h"

namespace OmPublic
{
    // Template class for creating single-instance global classes.
    template <typename T> class Singleton
    {
    	private:
    		static T* & ms_Singleton()
    		{
    			static T* msSingleton = 0;
    			return msSingleton;
    		}
    	public:
    		Singleton(void)
    		{
    			assert(!ms_Singleton());
    			ms_Singleton() = static_cast<T*> (this);
    		}
    		~Singleton(void)
    		{
    			assert(ms_Singleton());
    			ms_Singleton() = 0;
    		}
    	
    	static T & getSingleton(void)
    	{
    		//assert (ms_Singleton());
			
			// auto generate a instance. donot need explicit declaration.
			if (!ms_Singleton())				
			{
				T* t = new T; 
			}

    		return  (*ms_Singleton());
    	}
    	
    	static T * getSingletonPtr(void)
    	{
			if (!ms_Singleton())				
			{
				T* t = new T;
			}
    		return ms_Singleton();
    	}
    			
    };
}
#endif